package com.sright.bcard.mini.web.controller;

import com.aliyuncs.exceptions.ClientException;
import com.sright.bcard.common.service.share.dto.content.MessageDTO;
import com.sright.bcard.content.share.service.MessageService;
import com.sright.bcard.mini.web.constant.WebUrl;
import com.sright.bcard.user.share.request.TokenParam;
import com.sright.common.response.SrightResponse;
import com.taobao.api.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;

@RestController
public class CardMessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 获取推荐人姓名
     * @return
     */
    @GetMapping(WebUrl.Referrer)
    public SrightResponse referrer(@RequestAttribute TokenParam tokenParam) {
        return messageService.referrer(tokenParam.getMemberId());
    }

    /**
     * 申请企业名片
     * @return
     */
    @PostMapping(WebUrl.Message)
    public SrightResponse message(@RequestBody MessageDTO messageDTO,@RequestAttribute TokenParam tokenParam) throws NoSuchAlgorithmException, ApiException, InvalidKeyException, UnsupportedEncodingException, ClientException, ParseException {
        messageDTO.setMemberId(tokenParam.getMemberId());
        return messageService.addMessage(messageDTO);
    }

}
